package com.baselibrary.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class AmountUtil {
    public static String changeF2Y(String amount) throws Exception {
        if (!amount.matches("\\-?[0-9]+")) {
            throw new Exception("金额格式有误："+amount);
        }
        return BigDecimal.valueOf(Long.valueOf(amount)).divide(new BigDecimal(100)).toString();
    }

    public static String changeF2YKeepTwo(String amount) throws Exception {
        if (!amount.matches("\\-?[0-9]+")) {
            throw new Exception("金额格式有误");
        }
        return BigDecimal.valueOf(Long.valueOf(amount)).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP).toString();
    }
}
